--
-- Author: ping.wang
-- Date: 2019-07-31 17:15:10
--
-- JewelStarView
--

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.JewelStarScene

function ClassRef:init()
    display.setCascadeOpacityEnabled(self._root, true)
    self._ui.Button_close:addClickEventListener(function()
        self:closeView()
    end)

    self._nodeCurrent = self._ui["Panel/Panel_content/node_1"]
    self._panelNext = self._ui["Panel/Panel_content/Panel_next"]
    self._nodeNext = self._ui["Panel/Panel_content/Panel_next/node_2"]
    self._showDetailButton = self._ui["Panel/Button"]
    self._showDetailButton:addClickEventListener(function()
       --todo 准备跳转到详细属性界面
    end)

    --升级到最高级的时候隐藏掉
    self._maxPanel = self._ui["Panel/Panel_content/Panel_max"]


    local curScore = UD:getCurEquipedJewelScore()
    local masterConf = GD:getJewelMastersByClass(UD:getClass())
    local curInfo, nexInfo
    for k,v in ipairs(masterConf) do
        if curScore >= checknumber(v.pointNum) then
            curInfo = v
        else
            nexInfo = v
            break
        end
    end

    if not nexInfo then
        self._panelNext:setVisible(false)
        self._maxPanel:setVisible(true)
        --只初始化当前属性面板
        self:initPropertyPanel(self._nodeCurrent, curInfo, nexInfo, false, curScore)
    else
        self._panelNext:setVisible(true)
        self._maxPanel:setVisible(false)

        --准备初始化当前属性面板 和 下一级属性面板
        self:initPropertyPanel(self._nodeCurrent, curInfo, nexInfo, false, curScore)
        self:initPropertyPanel(self._nodeNext, curInfo, nexInfo, true, curScore)
    end
end

--isNext只是为了初始化开头的标题内容
function ClassRef:initPropertyPanel(panel, curInfo, nextInfo, isNext, curScore)
    if isNext then
        panel:findChild("Panel/tlt"):setString(L("jewel_master_string4"))
        panel:findChild("Panel/num"):setString(nextInfo.pointNum)
        local numText
        --需要跟cur比较 若高于 则显示绿色 否则显示灰色
        for i = 1, 4 do
            numText = panel:findChild(string.format("Panel/Panel_%d/num",i))
            numText:setString("+"..nextInfo["addType"..i])
            if checknumber(curInfo["addType"..i]) < checknumber(nextInfo["addType"..i]) then
                numText:setTextColor(cc.c3b(0,255,0))
            else
                numText:setTextColor(cc.c3b(255,255,255))
            end
        end

    else
        panel:findChild("Panel/tlt"):setString(L("jewel_master_string3"))
        panel:findChild("Panel/num"):setString(tostring(curScore))

        for i = 1, 4 do
            panel:findChild(string.format("Panel/Panel_%d/num",i)):setString("+"..curInfo["addType"..i])
        end
    end
end

return ClassRef
